package com.base.vistter.iframe.inverter.controller;

import com.base.vistter.iframe.bean.Result;
import com.base.vistter.iframe.entity.SysMenu;
import com.base.vistter.iframe.exception.IframeException;
import com.base.vistter.iframe.service.SysMenuService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Slf4j
@RequestMapping("/sys/menu")
public class SysMenuController {

    @Resource(name = "sysMenuService")
    private SysMenuService sysMenuService;

    @GetMapping
    public Result<List<SysMenu>> getList(String name) throws IframeException {
        return Result.ok(sysMenuService.getList(name));
    }

    @GetMapping("/{id}")
    public Result<SysMenu> get(@PathVariable("id") Integer id) throws IframeException {
        return Result.ok(sysMenuService.getById(id));
    }

    @PostMapping(produces = "application/json;charset=utf-8")
    public Result<Boolean> save(@RequestBody SysMenu sysDict) throws IframeException {
        return Result.ok(sysMenuService.save(sysDict));
    }

    @PutMapping(produces = "application/json;charset=utf-8")
    public Result<Boolean> update(@RequestBody SysMenu sysMenu) throws IframeException {
        return Result.ok(sysMenuService.update(sysMenu));
    }

    @DeleteMapping("/{id}")
    public Result<Integer> delete(@PathVariable("id") Integer id) throws IframeException {
        return Result.ok(sysMenuService.delete(id));
    }
    @GetMapping("/status")
    public Result<Boolean> status(@RequestParam("id") Integer id, @RequestParam("status") Integer status) throws IframeException {
        SysMenu sysMenu = new SysMenu();
        sysMenu.setId(id);
        sysMenu.setStatus(status);
        return Result.ok(sysMenuService.updateById(sysMenu));
    }
    @GetMapping("/tree")
    public Result<List<SysMenu>> getTreeData(Integer code) throws IframeException{
        return Result.ok(sysMenuService.getTreeData(code));
    }

    @GetMapping("/getUserMenu")
    public Result<List<SysMenu>> getUserMenu() throws IframeException {
        return Result.ok(sysMenuService.getUserMenu());
    }

    @GetMapping("/getEnableMenu")
    public Result<List<SysMenu>> getEnableMenu() throws IframeException {
        return Result.ok(sysMenuService.getEnableMenu());
    }

}
